package com.example.back_code.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.back_code.entity.po.Paper;
import com.example.back_code.mapper.PaperMapper;
import com.example.back_code.service.PaperService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class PaperServiceImpl extends ServiceImpl<PaperMapper, Paper> implements PaperService {
    @Override
    public boolean auditPaper(Long id, Integer status, String rejectReason) {
        Paper paper = getById(id);
        if (paper == null) return false;
        paper.setStatus(status);
        if (status != null && status == 2) {
            paper.setRejectReason(rejectReason);
        }
        return updateById(paper);
    }

    @Override
    public List<Paper> filterPapers(String paperName, String startDate, String endDate, String retrievalLevel, Integer status) {
        QueryWrapper<Paper> wrapper = new QueryWrapper<>();
        if (StringUtils.hasText(paperName)) {
            wrapper.like("paper_name", paperName);
        }
        if (StringUtils.hasText(startDate)) {
            wrapper.ge("publish_date", startDate);
        }
        if (StringUtils.hasText(endDate)) {
            wrapper.le("publish_date", endDate);
        }
        if (StringUtils.hasText(retrievalLevel)) {
            wrapper.eq("retrieval_level", retrievalLevel);
        }
        if (status != null) {
            wrapper.eq("status", status);
        }
        return list(wrapper);
    }
} 